#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   Bootloader_RequestTransferExit_0x37_test.py
@Time    :   2022/10/13 11:16:25
@Author  :   Yang Liang
@Version :   1.0
@Contact :   yangliang@chengtech.com
@License :   (C)Copyright 2022-2025
@Desc    :   None
'''

# here put the import lib
from numpy import byte, bytes_, int16
from pytest_assume.plugin import assume
 
import pytest
import time
import requests
from sympy import I
# from sympy import assuming
from commDriver.TS_CAN import *
import allure
import sys
from collections.abc import Iterable

from sqlalchemy import false
sys.dont_write_bytecode = True

SID_0x37_RequestTransferExit_NRC = [([0x37,0x01],[0x7F,0x37,0x13],[0x37]),            
                                    ([0x37,0x00,0xFF],[0x7F,0x37,0x13],[0x37,0x00,0xFF]),
                                    ([0x37,0x01,0xFF],[0x7F,0x37,0x13],[0x37,0x01,0xFF]),
                                    ([0x37,0x03],[0x7F,0x37,0x13],[0x37,0x03]),
                                    ([0x37,0x02],[0x7F,0x37,0x13],[0x37,0x02])]  
                              
class Test_RequestTransferExit_Phy(object):
     @allure.severity('minor')
     @allure.description('Test NRC24 of 0x37 in programming session in bootloader with physical addressing')
     @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/62a69d6cb35db4f20e37703a/cases')
     def test_RequestTransferExit_NRC24_Phy(self,Driver,action):
          iStep = 1
          iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x37], [0x7F,0x37,0x24], 2, iStep, True)


     ids = ["Request {2}".format(req,resp,binascii.b2a_hex(bytearray(send),' ')) for req,resp,send in SID_0x37_RequestTransferExit_NRC]
     @allure.severity('minor')
     @allure.description('Test NRC7F of 0x37 in bootloader with physical addressing')
     @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/62a69d6cb35db4f20e37703a/cases')
     @pytest.mark.parametrize('req,resp,title',SID_0x37_RequestTransferExit_NRC,ids = ids)
     def test_RequestTransferExit_NRC13_Phy(self,Driver,action,req,resp,title):
          iStep = 1
          iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, True)

     
     @allure.severity('minor')
     @allure.description('Test NRC7F of 0x37 in programming session in bootloader with physical addressing')
     @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/62a69d6cb35db4f20e37703a/cases')
     def test_RequestTransferExit_NRC7F_Default_Phy(self,Driver,action):
          iStep = 1
          iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x37], [0x7F,0x37,0x7F], 1, iStep, False)

     @allure.severity('minor')
     @allure.description('Test NRC7F of 0x37 in programming session in bootloader with physical addressing')
     @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/62a69d6cb35db4f20e37703a/cases')
     def test_RequestTransferExit_NRC7F_Extended_Phy(self,Driver,action):
          iStep = 1
          iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x37], [0x7F,0x37,0x7F], 3, iStep, True)
     
         

    
     
     